From eb76c1f16cb5e259e087d4045b80ce5528adef6f Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 1 Feb 2008 01:35:55 +0000 Subject: [PATCH] Fix a regression of bug 4899 due to HHPv2: tags now appear on tree depth levels other than the first. The 4899 aspect is easily fixed by having extractSections() look at the i attribute instead of just counting. The implications in general are that headings inside properly-closed double braces will not have section edit links, even where the braces are broken by invalid title characters and expanded literally to recover the heading. Respecting such headings as section breaks would run into the same problems as those discussed w.r.t. LST on wikitech-l -- there's no way to recover the text for a section that starts on one tree level and finishes on a different one. The fact that higher level nodes appear in the XML is just due to a shortcut in preprocessToObj(): headings are put into the stack in case the braces turn out to be unclosed, in which case the heading will be at level 1 of the tree. --- includes/Parser.php | 17 ++++++----------- includes/Preprocessor_DOM.php | 6 +++++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 5f56c0dbdc..418792a8e4 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -4572,7 +4572,6 @@ class Parser $this->setTitle( $wgTitle ); // not generally used but removes an ugly failure mode $this->mOptions = new ParserOptions; $this->setOutputType( self::OT_WIKI ); - $curIndex = 0; $outText = ''; $frame = $this->getPreprocessor()->newFrame(); @@ -4597,22 +4596,19 @@ class Parser // Section zero doesn't nest, level=big $targetLevel = 1000; } else { - while ( $node ) { - if ( $node->getName() == 'h' ) { - if ( $curIndex + 1 == $sectionIndex ) { + while ( $node ) { + if ( $node->getName() == 'h' ) { + $bits = $node->splitHeading(); + if ( $bits['i'] == $sectionIndex ) { + $targetLevel = $bits['level']; break; } - $curIndex++; } if ( $mode == 'replace' ) { $outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG ); } $node = $node->getNextSibling(); } - if ( $node ) { - $bits = $node->splitHeading(); - $targetLevel = $bits['level']; - } } if ( !$node ) { @@ -4627,10 +4623,9 @@ class Parser // Find the end of the section, including nested sections do { if ( $node->getName() == 'h' ) { - $curIndex++; $bits = $node->splitHeading(); $curLevel = $bits['level']; - if ( $curIndex != $sectionIndex && $curLevel <= $targetLevel ) { + if ( $bits['i'] != $sectionIndex && $curLevel <= $targetLevel ) { break; } } diff --git a/includes/Preprocessor_DOM.php b/includes/Preprocessor_DOM.php index 0fa48c46f7..0cd9df3b95 100644 --- a/includes/Preprocessor_DOM.php +++ b/includes/Preprocessor_DOM.php @@ -955,7 +955,11 @@ class PPFrame_DOM implements PPFrame { # Heading $s = $this->expand( $contextNode->childNodes, $flags ); - if ( $this->parser->ot['html'] ) { + # Insert a heading marker only for children of + # This is to stop extractSections from going over multiple tree levels + if ( $contextNode->parentNode->nodeName == 'root' + && $this->parser->ot['html'] ) + { # Insert heading index marker $headingIndex = $contextNode->getAttribute( 'i' ); $titleText = $this->title->getPrefixedDBkey(); -- 2.20.1